package cn.zymall.user.controller;

import cn.zymall.common.model.Collect;
import cn.zymall.common.model.Spu;
import cn.zymall.user.service.CommodityGoodsService;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * @author : th
 * @ClassName: commodityGoodsController
 * @Description : 商品收藏控制器
 * @date 2020年08月18日 20:19
 **/
@RequestMapping("/commodityGoods")
@RestController
public class CommodityGoodsController {


    @Autowired
    private CommodityGoodsService goodsService;


    /**
     * @author：th
     * @Description：查询用户收藏的所有商品
     * @Param：用户ID
     * @return：List<Spu>
     **/
    @GetMapping("/findAll")
    public PageInfo<Collect> findAll(int id, int page, int rows){
        return goodsService.findAll(id, page, rows);
    }

    /**
     * @author：th
     * @Description：模糊查询收藏商品
     * @Param：用户ID，商品名称
     * @return：List<Spu>
     **/
    @GetMapping("/collectFuzzy")
    public PageInfo<Collect> collectFuzzy(int id,String value,int page,int rows){
        System.out.println(id+"/"+value+"/"+page+"/"+rows);
        return goodsService.collectFuzzy(id, value, page, rows);
    }


    /**
     * @author：th
     * @Description：查询收藏表，有就修改，没有就添加
     * @Param：Collect
     * @return：boolean
     **/
    @PostMapping("/collectSave")
    public boolean collectSave(@RequestBody Collect collect){
        System.out.println(collect);
        return goodsService.collectSave(collect);
    }


    /**
     * @author：th
     * @Description：商品收藏删除
     * @Param：用户id，list
     * @return：Boolean
     **/
    @DeleteMapping("/collectRemove")
    public boolean collectRemove(@Param("id") int id,List list){
        return goodsService.collectRemove(id,list);
    }

    /**
     * 修改
     * @param collect
     * @return
     */
    @PutMapping("/updateById")
    public boolean updateById(@RequestBody Collect collect){
       return goodsService.updateById(collect);
    }

    /**
     * 删除
     * @param collect
     * @return
     */
    @DeleteMapping("deleteById")
    public boolean deleteById(@RequestBody Collect collect){
        return goodsService.deleteById(collect);
    }
}
